<!--本页面由uniapp切片工具生成，uni-app切片-可视化设计工具(一套代码编译到7个平台iOS、Android、H5、小程序)，软件下载地址：http://www.ymznkf.com/new_view_669.htm -->
<template>
	<view class="content">
		<titleXX :parentTitle="title"></titleXX>
		<view class="head">
			<view class="title">
				订单信息
			</view>
			<view class="title_message">
				<!-- <view class="title_number">订单编码：{{ DDBM }}</view> -->
				<view class="title_order">订单分类：{{ DDMC }}</view>
				<view class="title_time">
					<text>下单时间：</text> {{ nowDate }}{{ nowTime }}
				</view>
				<view class="title_time" v-if="LQSJ">
					<text>{{ DDMC == '共享衣柜' ? '取衣日期':'归还日期' }} ：</text> {{ LQSJ }}
				</view>
			</view>
		</view>
		<view class="between"></view>
		<view class="info">
			<view class="title">商品信息</view>
			<view class="info_list" v-for="item in list">
				<view class="list_item">
					<view class="item_img">
						<u-image :src="item.goodImage" width="100px" height="100px" shape="circle"></u-image>
						<text style="margin-left: 20rpx;">{{ item.goodName }}</text>
					</view>
					<view class="item_text">
						<view>
							￥{{ item.goodPrice }}
						</view>
						<view style="color: #909399;">
							X{{ item.goodQty ? item.goodQty : 1 }}
						</view>
					</view>
				</view>
			</view>
			<view class="total">￥{{ total }}</view>
		</view>
		<view class="between"></view>
		<!-- <view class="foot">
      <view class="title">
        人员信息
      </view>
      <view class="personMessage">
        <view>
          姓名：{{ resData.personName }}
        </view>
        <view>
          电话：{{ resData.personMobile }}
        </view>
      </view>
      <view class="personMessage">
        <view>
          类型：驿站服务项目
        </view>
        <view>
          状态：已完成
        </view>
      </view>
    </view> -->
		<view class="print">
			<view class="btn" @click="printOrder">预 约</view>
		</view>
		<!-- <view class="detail_bottom"></view> -->
	</view>
</template>

<script>
	import {
		getAccessToken
	} from "@/common/YYSLxx.js"
	// import order_completion from "./order_completion.js";
	import moment from 'moment'
	import titleXX from "@/components/title.vue"
	// import { getAccessToken } from "@/common/RLSB.js"

	// const plug = uni.requireNativePlugin('Html5app-Gprinter');
	export default {
		components: {
			titleXX,
		},
		onLoad() {
			// this.resData = JSON.parse(options.value)
			this.getTotalPrice()
			this.getNowTimeDate()
			// this.getNumber()
			this.createOrder()
		},

		data() {
			return {
				siteData: uni.getStorageSync('siteData') || {},
				title: "订单信息",
				resData: {},
				list: [],
				total: 0,
				nowTime: "",
				nowDate: "",
				DDMC: uni.getStorageSync('DDMC'),
				DDBM: null,
				deviceName: uni.getStorageSync('deviceName'),
				LQSJ: uni.getStorageSync('LQSJ'),
			}
		},
		created() {
			let arrayString = uni.getStorageSync('SPXX')
			const decodedString =decodeURIComponent(arrayString.replace(/%25/g, '%'));
			this.list =JSON.parse(decodedString)
		},
		methods: {
			getNowTimeDate() {

				let now = new Date();
				let year = now.getFullYear();
				let month = String(now.getMonth() + 1).padStart(2, '0');
				let day = String(now.getDate()).padStart(2, '0');

				let hours = ('0' + now.getHours()).slice(-2);
				let minutes = ('0' + now.getMinutes()).slice(-2);
				let seconds = ('0' + now.getSeconds()).slice(-2);

				this.nowTime = hours + ':' + minutes + ':' + seconds;
				this.nowDate = year + '年' + month + '月' + day + '日';
			},
			getTotalPrice() {
				let arrayString = uni.getStorageSync('SPXX')
				let decodedString  = decodeURIComponent(arrayString.replace(/%25/g, '%'));
				let data = JSON.parse(decodedString)
				let spList = data.map(item => {
					this.total += (item.number || item.goodQty) * item.goodPrice
					delete item.creationTime;
					delete item.lastUpdateTime;
					return item
				})
				let li = encodeURIComponent(JSON.stringify(spList).replace(/%/g, '%25'))
				uni.setStorageSync('SPXX', li)
			},
			createOrder() {},
			printOrder() {
				uni.showLoading({
					title: "订单生成中...",
					mask: true
				})
				// getAccessToken()
				uni.hideLoading()
				const currentTimeStamp = moment().unix();
				const min = BigInt('1' + '0'.repeat(18));
				const max = BigInt('1' + '0'.repeat(19));
				const randomNum = min + BigInt(Math.floor(Math.random() * Number(max - min)));
				let arrayString = uni.getStorageSync('SPXX')
				let decodedString = decodeURIComponent(arrayString.replace(/%25/g, '%'));
				let goodMessage = JSON.parse(decodedString)
				let itemXX = {
					SBBT: '共享菜单',
					orderNumber: currentTimeStamp + randomNum.toString(), //预约编号
					siteId: this.siteData.id, //服务点id
					orderProject: uni.getStorageSync('DDMC'), //预约项目
					orderProjectType: "0", //0:   1:  (区分健康自测类型与其他类型)
					orderCreationTime: moment().format("YYYY-MM-DD"), //下单时间
					goodInfo: uni.getStorageSync("SPlist"),
					estimateArrivalTime: this.LQSJ, //服务时间
					estimateArrivalTimeTitle: "取衣日期",
					estimateSumPrice: this.total, //预估费用
					orderSubType: "", //预约类型
					serviceDescription: "", //服务介绍
					orderLocation: "", //预约地址(非空展示)
					serviceTip: "", //温馨提示(非空展示)
					goodSumPrice: "", //总价
					serviceTitleList: ["商品名称", "单价", "数量", "小计"], //服务标题
					goodList: [], //商品列表, 
				}
				goodMessage.forEach(item => {
					let obj = {
						goodId: item.goodId,
						goodName: item.goodName,
						servicePrice: item.goodPrice,
						serviceQty: item.goodQty,
						goodCountPrice: item.goodPrice * item.goodQty,
						serviceProjectName: "",
						remark: "",
						serviceMessage: "",
					}
					itemXX.goodList.push(obj)
				})
				// let li = encodeURIComponent(JSON.stringify(itemXX))
				// uni.redirectTo({
				// 	url: `/pages/SXT/faceImg?YYXQxx=` + li
				// })
				getAccessToken(itemXX, '共享菜单')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		font-size: 28rpx;
		margin: 10rpx;
	}

	.info {
		margin: 0 auto;
		width: 95%;
		height: calc(100vh - 500rpx);
		overflow-y: scroll;
		overflow-x: hidden;
	}

	.between {
		height: 20rpx;
		width: 95%;
		margin: 0 auto;
		border-radius: 30rpx;
		background-color: #f4f4f5;

	}

	.head {
		margin: 0 auto;
		width: 95%;
		padding: 20rpx 0;

		.title_message {
			margin-left: 10rpx;
			font-size: 24rpx;
			color: #909399;

			view {
				margin: 8rpx 0;
			}
		}
	}

	.info {
		width: 95%;
		margin: 0rpx auto;
		padding: 20rpx 0;
		box-sizing: border-box;

		.info_list {
			display: flex;
			flex-direction: column;

			.list_item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 26rpx;
				padding: 10rpx;
				border-bottom: 1px solid #c8c9cc;
				border-top: 1px solid #c8c9cc;

				.item_img {
					flex: 2;
					display: flex;
					align-items: center;
				}

				.item_text {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: space-around;
				}
			}
		}

		.total {
			margin-top: 10rpx;
			text-align: right;
			font-size: 28rpx;
			color: #027571;
			font-weight: bold;
			padding-right: 50rpx;
		}
	}

	.foot {
		margin: 0 auto;
		width: 95%;
		padding: 20rpx 0;

		.personMessage {
			display: flex;
			align-items: center;
			margin: 10rpx;
			font-size: 24rpx;
			color: #909399;

			view {
				flex: 1;
			}
		}
	}

	.detail_bottom {
		height: 100rpx;
		background-color: #ffffff;
	}

	.print {
		bottom: 10rpx;
		width: 100%;
		height: 90rpx;
		background-color: #ffffff;
		border: none;
		margin-top: 30rpx;

		.btn {
			width: 90%;
			margin: 0 auto;
			padding: 10rpx 0;
			text-align: center;
			line-height: 60rpx;
			height: 60rpx;
			font-size: 28rpx;
			border-radius: 20rpx;
			background-color: #027571;
			color: #fff;
		}

	}
</style>